/*---------------------------------------------------------------
 * Confidential and Proprietary
 * Copyright 2006 CMO & Hewlett-Packard Development Company, L.P.
 * All Rights Reserved
 *---------------------------------------------------------------
 * Project Name    : SPF
 *
 * Class Name      : MenuConfig
 * Purpose         : As a singleton storing the contents of
 *                   MenuConfig.xml
 *---------------------------------------------------------------
 * Modification Log
 * Date         Ver. #      Programmer       Description
 *
 * 2006-3-29    1.1         Zhang WeiDong    Initial Creation
 *---------------------------------------------------------------
 */
package com.erdos.common.util;

import java.io.IOException;
import java.io.InputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.xml.sax.SAXException;

/**
 *  As a singleton storing the contents of MenuConfig.xml.
 *  @author Zhang WeiDong<br>
 *  Create Date: 2006-3-29
 */
public class MenuConfig {

	/** MenuConfig.xml -- System menu XML file name. */
    public static final String SYSTEM_MENU_XML="/menuConfig.xml";
	
    /** The internal class-wide XML DOM document object. */
    //private static Document xml=null;
    
    /** protected constructor for singleton. */
    protected MenuConfig() {
        // nothing
    }
    
    /**
     * Initialize class-wide MenuConfig instance.
     * @param path The path to MenuConfig.xml file.
     * @throws ParserConfigurationException
     * @throws SAXException
     * @throws IOException<br>
     * Modifier: 2006-3-29 Zhang WeiDong Create
     */
    public static Document getXml() throws ParserConfigurationException, SAXException, IOException {
        Document xml = null;
    	if (xml == null) {
			DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
			DocumentBuilder db = dbf.newDocumentBuilder();
			InputStream is = MenuConfig.class.getResourceAsStream(SYSTEM_MENU_XML);
			xml = db.parse(is);
		}
        return xml;
}
    
    /**
     * Get the XML contents of MenuConfig (initialize if needed).
     * @return The XML DOM object containing MenuConfig, or null if not initialized.
     * Modifier: 2006-3-29 Zhang WeiDong Create
     */
/*    public static Document getXml() {
        return xml;
    }*/
}
